package com.wiretap.util;

import java.io.Serializable;

/**
 * @author zzy
 * @catagory 常用工具类
 */
public class CommenUtil implements Serializable{
	private static final long serialVersionUID = -3795723695097712560L;

	/**
	 * 字符串是否為NULL
	 * 
	 * @param target
	 * @return
	 */
	public static boolean isNull(String target) {
		if (target == null || target.toLowerCase().equals("null")) {
			return true;
		}
		return false;
	}

	/**
	 * 字符串是否為空
	 * 
	 * @param target
	 * @return
	 */
	public static boolean isEmpty(String target) {
		if (target == null || target.trim().length() < 1) {
			return true;
		}
		return false;
	}

	/**
	 * 將target轉換為字符串
	 * 
	 * @param target
	 * @return
	 */
	public static String getString(Object target) {
		if (target == null)
			return null;
		return String.valueOf(target);
	}

	/**
	 * 将字符串转换为数字
	 * 
	 * @param tar
	 * @return
	 */
	public static int getInteger(String tar) {
		int re = 0;
		try {
			re = Integer.parseInt(tar);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return re;
	}

	/**
	 * 将字符串转换为浮點數
	 * 
	 * @return
	 */
	public static double getDouble(String tar) {
		double re = 0.0;
		if (isEmpty(tar)) {
			return re;
		}
		try {
			re = Double.parseDouble(tar);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return re;
	}

	/**
	 * 将字符串转换为浮點數
	 * 
	 * @return
	 */
	public static long getLong(String tar) {
		long re = 0;
		if (isEmpty(tar)) {
			return re;
		}
		try {
			re = Long.parseLong(tar);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return re;
	}

	/**
	 * 将字符串转换为浮點數
	 * 
	 * @return
	 */
	public static long getLong(Object tar) {
		long re = 0;
		String sLong = getString(tar);
		if (isEmpty(sLong)) {
			return re;
		}
		try {
			re = Long.parseLong(sLong);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return re;
	}
}
